package com.example.controller;

import com.example.common.Result;
import com.example.model.dto.CourseRequest;
import com.example.model.entity.Course;
import com.example.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/backend/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/list")
    public Result<List<Course>> listCourses() {
        return Result.success(courseService.listCourses());
    }


    @GetMapping("/get/{id}")
    public Result<Course> getCourse(@PathVariable Integer id) {
        return Result.success(courseService.getCourseById(id));
    }

    @PostMapping("/add")
    public Result<Course> addCourse(@RequestBody CourseRequest courseRequest) {
        return Result.success(courseService.addCourse(courseRequest));
    }

    @PostMapping("/edit")
    public Result<Course> updateCourse(@RequestBody CourseRequest courseRequest) {
        return Result.success(courseService.updateCourse(courseRequest));
    }

    @DeleteMapping("/remove/{id}")
    public Result<Void> deleteCourse(@PathVariable Integer id) {
        courseService.deleteCourse(id);
        return Result.success(null);
    }
} 